package com.leo.train.business.controller.admin;

import com.leo.train.business.dto.StationDto;
import com.leo.train.business.dto.StationQueryDto;
import com.leo.train.business.entity.Station;
import com.leo.train.business.service.StationService;
import com.leo.train.common.resp.CommonResp;
import com.leo.train.common.resp.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/station")
public class AdminStationController {
    @Autowired
    private StationService stationService;
    /**
     * 添加
     * @param stationDto
     * @return
     */
    @PostMapping("/add")
    public CommonResp add(@RequestBody StationDto stationDto) {
         stationService.save(stationDto);
        return new CommonResp<>();
    }
    /**
     * 修改
     * @param stationDto
     * @return
     */
    @PostMapping("/update")
    public CommonResp update(@RequestBody StationDto stationDto) {
        stationService.save(stationDto);
        return new CommonResp<>();
    }
    /**
     * 列表
     * @param queryDto
     * @return
     */
    @GetMapping("/list")
    public CommonResp<PageResult> list(StationQueryDto queryDto) {
        PageResult pageResult = stationService.list(queryDto);
        return new CommonResp<>(pageResult);
    }
    /**
     * 详情
     */
    @GetMapping("/detail")
    public CommonResp<StationDto> detail(@RequestParam Long id) {
        StationDto stationDto = stationService.detail(id);
        return new CommonResp<>(stationDto);
    }

    /**
     * 删除
     * @param map
     * @return
     */
    @PostMapping("/delete")
    public CommonResp delete(@RequestBody Map<String, Long> map) {
        Long id = map.get("id");
        stationService.delete(id);
        return new CommonResp<>();
    }

    /**
     * 车站所有列表
     */
    @GetMapping("/listAll")
    public CommonResp<List<Station>> listAll() {
        List<Station> list = stationService.listAll();
        return new CommonResp<>(list);
    }


}
